package com.example.tao_city.text1;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

/**
 * Created by TAO_CITY on 2018/1/29.
 */

public class Myadapter extends BaseAdapter implements View.OnClickListener {
    private List<Tuikuang_Item> list;
    private Context context;
    private Callbac mCallback;

    /**
     * 自定义接口，用于回调按钮点击事件到Activity
     */
    public interface Callbac {
        public void click(View v);
    }

    public Myadapter(List list, Context context, Callbac mCallback) {
        this.context = context;
        this.list = list;
        this.mCallback = mCallback;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater la = LayoutInflater.from(context);
        convertView = la.inflate(R.layout.tuikuang_istview, null);

        TextView danghao = convertView.findViewById(R.id.tuikuang_listview_danghao);
        TextView shijian = convertView.findViewById(R.id.tuikuang_listview_shijian);
        TextView qian = convertView.findViewById(R.id.tuikuang_listview_qian);
        final TextView tuikuang = convertView.findViewById(R.id.tuikuang_listview_tuikuang);
        final TextView yituikuan = convertView.findViewById(R.id.tuikuang_listview_tuikuangtip);

        danghao.setText(list.get(position).getDanghao());
        shijian.setText(list.get(position).getShijian());
        qian.setText(list.get(position).getQian());
        tuikuang.setText(list.get(position).getTuikuang());
        yituikuan.setText(list.get(position).getYituikuan());

        tuikuang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder ab=new AlertDialog.Builder(context);
                ab.setTitle("确认退款");
                ab.setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        MyToast.makeText(context,"退款成功", Toast.LENGTH_SHORT).show();
                        tuikuang.setTextColor(Color.parseColor("#808080"));
                        tuikuang.setText("已退款");
                        yituikuan.setTextColor(Color.parseColor("#808080"));
                        android.os.Handler ha=new android.os.Handler();
                        ha.postDelayed(ma,2000);
                    }
                });
                ab.show();
                mCallback.click(v);
            }
        });
        return convertView;
    }


    @Override
    public void onClick(View v) {
    }
    Runnable ma=new Runnable() {
        @Override
        public void run() {
            Fm1_tuikuangshengqing.run=true;
        }
    };
}
